//
//  AlertKuangView.m
//  HappyZuApp
//
//  Created by 张丽敏 on 15/12/22.
//  Copyright © 2015年 Liang. All rights reserved.
//

#import "AlertKuangView.h"

@implementation AlertKuangView
#pragma mark - 设置自动消失的警告框
-(id)moveJingGaoKuang:(NSString *)imageStr :(UIView *)view
{
   CGFloat LabelWidth =  [self widthOfString:imageStr]+10;
//    label = [[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-LabelWidth)/2, ScreenHeight/2-30 ,LabelWidth , 35)];
    label = [[UILabel alloc]init];
    label.frame = CGRectMake( (ScreenWidth-LabelWidth)/2,ScreenHeight/2-30 , LabelWidth , 35 );
    label.text = imageStr;
    label.textAlignment = 1;
//    背景颜色
//   你可以修改成你们的背景颜色
    label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.75];
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    label.textAlignment = NSTextAlignmentCenter;
    [label.layer setMasksToBounds:YES];
//    设置圆角和外框的宽度
    [label.layer setCornerRadius:5.0];
    [label.layer setBorderWidth:1.0];
//    [label.layer setBorderColor:[UIColor bianKuangColor].CGColor];//边框的颜色
    [view addSubview:label];
//    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 0, 130*WidthScal, 60)];
//    imageView.center = view.center;
//    imageView.tag=1000;
//    imageView.image = [UIImage imageNamed:imageStr];
//    [view addSubview:imageView];
    view.userInteractionEnabled = NO;
    NSLog(@"显示");
    [self performSelector:@selector(delay) withObject:nil afterDelay:2];
    viewNew = view;
    return view;
}
#pragma mark - 动画
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context
{
    NSLog(@"消失1");

    [label removeFromSuperview];
    viewNew.userInteractionEnabled = YES;
}
-(void)delay
{
//    设置延时多长时间消失
    [UIView animateWithDuration:2 animations:^{
    } completion:^(BOOL finished) {
        NSLog(@"消失2");
        [label removeFromSuperview];
        viewNew.userInteractionEnabled = YES;
    }];
}
-(CGFloat)widthOfString:(NSString *)string
{
    NSDictionary * dict=[NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Arial" size:14] forKey:NSFontAttributeName];
    CGRect rect=[string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX,1000) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    return rect.size.width+10;
}
@end
